<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page import="com.samebuilding.util.WebUtil" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    
    <title></title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<script type='text/javascript' src='../javascript/jquery-1.2.6.js'></script>
	<script type='text/javascript' src='../javascript/jquery.json.js'></script>
	
  <script type='text/javascript' src='../dwr/interface/PhotoCategoryService.js'></script>
  <script type='text/javascript' src='../dwr/engine.js'></script>

  
	<script type="text/javascript">
	var $J = jQuery.noConflict();

	function update(category){
		alert('update');
		$J("#code").val(category.code);
		$J("#name").val(category.name);
		$J("#isPublic").attr('checked',category.isPublic);
	};
	function add(category){
		alert('add');
		$J("#code").val('');
		$J("#name").val('');
		$J("#isPublic").attr('checked',true);
	};
	
	function remove(code){
		PhotoCategoryService.deletePhotoCategory(code,function(){
			load();
			parent.loadCategory();
		})	
	};
	
	function upload(code){
		window.location='./upload.jsp?categoryCode='+code;
	};
	function load(){
				PhotoCategoryService.getAllPhotoCategory(
				function(categories){
					var tbody=getPhotoTableBody(categories);
					$J("#photo_category_data").html(tbody);
				}
			);
	}
	function save(){
		var category={};
		category.code=$J("#code").val();
		category.name=$J("#name").val();
		category.isPublic=$J("#isPublic").attr("checked");
		PhotoCategoryService.saveOrUpdatePhotoCategory(category,function(){alert('保存成功');
		load();
		});
	}
	function getPhotoTableBody(data){
		var renderer={
			name:function(str,id){return str},
			isPublic:function(str){if(str) return '是'; else return '否';},	
			update:function(str){return '<input type=\'button\' value=\'编辑\' onclick=\'update('+str+')\' />';},
			remove:function(str){return '<input type=\'button\' value=\'删除\' onclick=\'remove('+str+')\' />';},
			upload:function(str){return '<input type=\'button\' value=\'上传\' onclick=\'upload('+str+')\' />';}
			
					
		};
		var str='';
		for(var i=0;i<data.length;i++){
			var category=data[i];
		
			str+='<tr><td>'+renderer.name(category.name,category.code)+'</td><td>'+renderer.isPublic(category.isPublic)+
			'</td><td>'+renderer.remove(category.code)+'</td>';			
		}
		return str;
	}
	$J(load);
	</script>
 <style type="text/css">
table{border:1px solid #000;border-width:1px 0 0 1px;margin:0px 0 0px 0;text-align:center;border-collapse:collapse;}
td,th{border:1px solid #000;border-width:0 1px 1px 0;margin:0px 0 0px 0;text-align:left;}
th{text-align:center;font-weight:600;font-size:12px;background-color:#F4F4F4;}
</style>
  </head>
 
  <body>
  <table border="0" width="100%">
  <thead>
    <tr>
      <th>照片目录名称</th>
      <th>是否公开</th>
      <th>操作</th>
    </tr>
  </thead>
  <tbody id="photo_category_data">	
  </tbody>
</table>
<p>
<div align="center">
<input type="button" value="关闭" onclick="parent.$J.unblockUI();" />
</div>
</body>
</html>
